package com.ly.algorithm.offerpointer;
import	java.time.Instant;
import java.time.Duration;
import	java.time.LocalDate;
import	java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.TemporalUnit;
import java.util.Arrays;

/**
 * @Classname Offer17
 * @Description
 *
 *
 * 输入数字 n，按顺序打印出从 1 到最大的 n 位十进制数。比如输入 3，则打印出 1、2、3 一直到最大的 3 位数 999。
 *
 * 示例 1:
 *
 * 输入: n = 1
 * 输出: [1,2,3,4,5,6,7,8,9]
 *
 *
 * @Date 2021/1/26 19:46
 * @Author 冷心影翼
 */
public class Offer17 {

    public static void main(String[] args) {
        Solution17 solution17 = new Solution17();
        solution17.printNumbers(2);
//        Instant instant = Instant.now();
//        solution17.printNumbersByBigInteger(7);
//        System.out.println(Duration.between(instant,Instant.now()).toMillis());
        Instant instant2 = Instant.now();
        System.out.println(solution17.printNumbersDFS(7));
        Duration.between(instant2,Instant.now()).toMillis();
    }

}


class Solution17 {
    //小数
    public int[] printNumbers(int n) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append("9");
        }
        int max = Integer.parseInt(sb.toString());
        int[] res = new int[max];
        for (int i = 1; i <= max; i++) {
            res[i-1] = i;
        }
        return res;
    }

    //大数
    public String printNumbersByBigInteger(int n) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append("9");
        }
        BigInteger max = new BigInteger(sb.toString());
        sb = new StringBuilder("");
        for (BigInteger i = BigInteger.valueOf(1); i.compareTo(max)<1;i = i.add(BigInteger.ONE)) {
            sb.append(i+" ");
        }
        return sb.toString();
    }


    //全排列
    StringBuilder res;
    int n;
    char[] loop = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    public String printNumbersDFS(int n) {
        res = new StringBuilder();
        this.n = n;
        for (char c : loop ) {
            dfs("",c);
        }
        return res.toString();
    }

    void dfs(String s,char choose) {
        s+=choose;
        if(s.length() == n) {
            res.append(s+" ");
            return;
        }
        for (char c : loop ) {
            dfs(s,c);
        }
    }
}